package Reflex.获取实例;

import Reflex.类.Student;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class InstanceDemo {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        Class stuClass = Class.forName("Reflex.类.Student");
        //实例化一个对象
        //Object stuInstance = stuClass.newInstance();
         Student stuInstance = (Student)stuClass.newInstance();
        System.out.println("获取实例化对象:\t"+stuInstance);

        //获取类的方法
        Method method = stuClass.getMethod("getId");   // sout -->   public int 反射.类.Student.getId()

        //援引 这个方法
        Object invoke = method.invoke(stuInstance);  //sout --->  0 , 有返回值的 返回方法的返回值，可以用对应的返回值类型 来接收

    }
}
